package com.cyc.basic.controller;

import com.cyc.common.model.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CountDownLatch;

/**
 * @Description:
 * @version 1.0
 * @author cyc
 * @date 2021/9/10 17:42
 */
@RestController
@RequestMapping("/order")
public class OrderController {


    @GetMapping(value = "sell")
    public ApiResult<Void> sell(@RequestParam Integer id, @RequestParam Integer latchCount) {
        CountDownLatch latch = new CountDownLatch(latchCount);
        for (int i = 0; i < latchCount; i++) {
            new Thread(() -> {
                try {
                    latch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
            latch.countDown();
        }
        return ApiResult.success();
    }
}
